package com.jiuwu.spring.eshop.respository;

import com.jiuwu.spring.eshop.db.entity.Goods;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface GoodsRepository extends BaseRepository<Goods,Integer> {

    @Transactional
    @Modifying
    @Query(value = "update tb_Goods set goodsTypeID = :goodsTypeID, goodsName= :goodsName ," +
            "goodsType= :goodsType,goodsIntroduce= :goodsIntroduce,goodsPrice = :goodsPrice," +
            "GoodsNowPrice= :goodsNowPrice,goodsPicture= :goodsPicture,"+
            "isNew =:isNew,isSale= :isSale,goodsPicture1= :goodsPicture1,goodsPicture2=:goodsPicture2,"+
            "goodsPicture3=:goodsPicture3,goodsPicture4=:goodsPicture4,goodsPicture5=:goodsPicture5,"+
            "goodsPicture6=:goodsPicture6 "+
            "where goodsID = :goodsId",
            nativeQuery = true)
    void updateNameById(@Param("goodsTypeID") Integer goodsTypeID,
                        @Param("goodsName") String goodsName,
                        @Param("goodsType")String goodsType,
                        @Param("goodsIntroduce") String goodsIntroduce,
                        @Param("goodsPrice") float goodsPrice,
                        @Param("goodsNowPrice") float goodsNowPrice,
                        @Param("goodsPicture")String goodsPicture,
                        @Param("goodsPicture1")String goodsPicture1,
                        @Param("goodsPicture2")String goodsPicture2,
                        @Param("goodsPicture3")String goodsPicture3,
                        @Param("goodsPicture4")String goodsPicture4,
                        @Param("goodsPicture5")String goodsPicture5,
                        @Param("goodsPicture6")String goodsPicture6,
                        @Param("isSale")int isSale,
                        @Param("isNew")int isNew,
                        @Param("goodsId") Integer goodsId);


    /**
     * 查找最新的四个
     * @param isNew
     * @return
     */
    List<Goods> findTop4ByIsNewEqualsOrderByGoodsCreatedTimeDesc(int isNew);


    /**
     * 热度大于1 的
     * @param goodsHit
     * @return
     */
    List<Goods> findTop4ByGoodsHitGreaterThanOrderByGoodsCreatedTimeDesc(int goodsHit);

    /**
     * 查找正在销售的
     * @param isSale
     * @return
     */
    List<Goods> findTop4ByIsSaleEqualsOrderByGoodsCreatedTimeDesc(int isSale);


    Page<Goods> findAll(Pageable pageable);

}
